/*
 * Copyright @ 2024 weili23
 * com.sky.controller.admin 17:18
 * All right reserved.
 */

package com.sky.controller.admin;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sky.dto.DishDTO;
import com.sky.dto.DishPageQueryDTO;
import com.sky.entity.Category;
import com.sky.entity.Dish;
import com.sky.result.Result;
import com.sky.service.DishService;
import com.sky.vo.DishVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.util.List;

/**
 * @desc:
 * @author: weili23
 * @createTime: 2024/10/25 17:18
 * @version: v1.0
 */
@RequestMapping("/admin")
@Api(tags = "菜品相关接口")
@RestController
public class DishController {
    @Resource
    private DishService dishService;


    @PostMapping("/dish")
    @ApiOperation("新增菜品")
    public Result saveDishWithFlavor(@RequestBody DishDTO dishDTO){
        dishService.saveDishWithFlavor(dishDTO);
        return Result.success();
    }

    @GetMapping("/dish/page")
    @ApiOperation("分页查询")
    public Result<Page<DishVO>> pageQuery(DishPageQueryDTO dishPageQueryDTO){
        Page<DishVO> page = dishService.pageQuery(dishPageQueryDTO);
        return Result.success(page);
    }
    @DeleteMapping("/dish")
    @ApiOperation("删除操作")
    public Result deleteDish(String ids){
        dishService.deleteDish(ids);
        return Result.success();
    }

    @GetMapping("/dish/{id}")
    @ApiOperation("根据id查询详情")
    public Result<DishVO> selectById(@PathVariable String id){
        DishVO dishVO =dishService.selectById(id);
        return Result.success(dishVO);
    }

    @PutMapping("/dish")
    @ApiOperation("修改菜品")
    public Result updateDish(@RequestBody DishDTO dishDTO){
        dishService.updateDishWithFlavor(dishDTO);
        return Result.success();
    }
    @PostMapping("/dish/status/{status}")
    @ApiOperation("起售、停售")
    public Result onSaleOrStopSale(Long id,@PathVariable Integer status){
        dishService.onSaleOrStopSale(id,status);
        return Result.success();
    }

    @GetMapping("/dish/list")
    @ApiOperation("根据分类id查询菜品列表")
    public Result<List<Dish>> selectListByGateroyId(Long categoryId){
        List<Dish>  list =dishService.selectListByGateroyId(categoryId);
        return Result.success(list);
    }

}
